package com.the4man.cnbdw.action.action;

import com.the4man.cnbdw.utils.Page;
import com.the4man.framework.utils.DateJsonValueProcessor;
import com.the4man.framework.utils.JsonWrapper;
import net.sf.json.JSONObject;
import net.sf.json.JsonConfig;
import net.sf.json.util.CycleDetectionStrategy;

import java.io.File;
import java.util.Calendar;
import java.util.Date;

public class BaseForm<T> {
    private String id;
    private String ids;
    private Integer level;
    private String typeIndex;
    private Integer curPage = Integer.valueOf(1);
    private Integer rowsPerPage = Integer.valueOf(36);
    private Integer totalPage;
    private Integer totalCount = Integer.valueOf(0);
    private Page<T> pageSource = new Page();
    private Integer reviewPageRowPerPage = Integer.valueOf(10);
    private Integer commentRowPerPage = Integer.valueOf(5);
    private Integer addressRowPerPage = Integer.valueOf(5);
    private Integer favoritesRowPerPage = Integer.valueOf(12);
    private Integer orderRowPerPage = Integer.valueOf(5);
    private Integer reviewRowPerPage = Integer.valueOf(5);
    private Integer feedbackRowPerPage = Integer.valueOf(10);
    private Integer feedbackInfoRowPerPage = Integer.valueOf(10);
    private Integer tagRowPerPage = Integer.valueOf(45);
    private Integer couponRowPerPage = Integer.valueOf(10);
    private Integer start = Integer.valueOf(1);
    private Integer limit = Integer.valueOf(10);
    private String jsonText;
    private String popMessage;
    private boolean resultBoolean;
    private String jsonObjectText;
    private File[] upFile;
    private String[] upFileFileName;

    public BaseForm() {
    }

    public String getJsonText() {
        return this.jsonText;
    }

    public void setJsonText(String jsonText) {
        this.jsonText = jsonText;
    }

    public void setJsonMsg(Object data) {
        this.setJsonMsg(this.popMessage, this.resultBoolean, data);
    }

    public void setJsonMsg(String msg, boolean flag, Object data) {
        JsonWrapper wrapper = new JsonWrapper(flag, msg, data);
        JsonConfig config = new JsonConfig();
        config.registerJsonValueProcessor(Date.class, new DateJsonValueProcessor("yyyy-MM-dd HH:mm:ss"));
        this.setJsonText(JSONObject.fromObject(wrapper, config).toString());
    }

    public void setJsonMsg(String msg, boolean flag, Object data, String formart) {
        JsonWrapper wrapper = new JsonWrapper(flag, msg, data);
        JsonConfig config = new JsonConfig();
        config.registerJsonValueProcessor(Date.class, new DateJsonValueProcessor(formart));
        this.setJsonText(JSONObject.fromObject(wrapper, config).toString());
    }

    public void setJsonObject(Object data) {
        JsonConfig config = new JsonConfig();
        config.registerJsonValueProcessor(Date.class, new DateJsonValueProcessor("yyyy-MM-dd HH:mm:ss"));
        config.setCycleDetectionStrategy(CycleDetectionStrategy.LENIENT);
        this.setJsonObjectText(JSONObject.fromObject(data, config).toString());
    }

    public void setJsonMsg() {
        this.setJsonMsg(this.popMessage, this.resultBoolean, (Object)null);
    }

    public Integer getTotalCount() {
        return this.totalCount;
    }

    public void setTotalCount(Integer totalCount) {
        this.totalCount = totalCount;
    }

    public void setPageSource(Page<T> pageSource) {
        this.pageSource = pageSource;
    }

    public Integer getRowsPerPage() {
        return this.rowsPerPage;
    }

    public void setRowsPerPage(Integer rowPerPage) {
        if (rowPerPage != null && rowPerPage.intValue() >= 0) {
            this.rowsPerPage = rowPerPage;
            this.pageSource.setRowsPerPage(rowPerPage.intValue());
        } else {
            this.rowsPerPage = this.pageSource.getRowsPerPage();
        }

    }

    public Integer getCurPage() {
        return this.curPage;
    }

    public Integer getTotalPage() {
        return this.totalPage;
    }

    public void setTotalPage(Integer totalPage) {
        this.totalPage = totalPage;
    }

    public void setCurPage(Integer curPage) {
        if (curPage == null || curPage.intValue() < 0) {
            curPage = Integer.valueOf(1);
        }

        this.curPage = curPage;
        this.pageSource.setCurPage(curPage.intValue());
    }

    public static void main(String[] args) {
        int y = Calendar.getInstance().get(1);
        int m = Calendar.getInstance().get(2);
        System.out.println(y + ":" + m);
    }

    public String getJsonObjectText() {
        return this.jsonObjectText;
    }

    public void setJsonObjectText(String jsonObjectText) {
        this.jsonObjectText = jsonObjectText;
    }

    public Integer getLimit() {
        return this.limit;
    }

    public void setLimit(Integer limit) {
        this.limit = limit;
    }

    public Integer getStart() {
        return this.start;
    }

    public void setStart(Integer start) {
        this.start = start;
    }

    public String getId() {
        return this.id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getIds() {
        return this.ids;
    }

    public void setIds(String ids) {
        this.ids = ids;
    }

    public File[] getUpFile() {
        return this.upFile;
    }

    public void setUpFile(File[] upFile) {
        this.upFile = upFile;
    }

    public String[] getUpFileFileName() {
        return this.upFileFileName;
    }

    public void setUpFileFileName(String[] upFileFileName) {
        this.upFileFileName = upFileFileName;
    }

    public Page<T> getPageSource() {
        return this.pageSource;
    }

    public Integer getLevel() {
        return this.level;
    }

    public void setLevel(Integer level) {
        this.level = level;
    }

    public Integer getCommentRowPerPage() {
        return this.commentRowPerPage;
    }

    public void setCommentRowPerPage(Integer commentRowPerPage) {
        this.commentRowPerPage = commentRowPerPage;
    }

    public Integer getAddressRowPerPage() {
        return this.addressRowPerPage;
    }

    public void setAddressRowPerPage(Integer addressRowPerPage) {
        this.addressRowPerPage = addressRowPerPage;
    }

    public Integer getFavoritesRowPerPage() {
        return this.favoritesRowPerPage;
    }

    public void setFavoritesRowPerPage(Integer favoritesRowPerPage) {
        this.favoritesRowPerPage = favoritesRowPerPage;
    }

    public Integer getOrderRowPerPage() {
        return this.orderRowPerPage;
    }

    public void setOrderRowPerPage(Integer orderRowPerPage) {
        this.orderRowPerPage = orderRowPerPage;
    }

    public Integer getReviewRowPerPage() {
        return this.reviewRowPerPage;
    }

    public void setReviewRowPerPage(Integer reviewRowPerPage) {
        this.reviewRowPerPage = reviewRowPerPage;
    }

    public Integer getFeedbackRowPerPage() {
        return this.feedbackRowPerPage;
    }

    public void setFeedbackRowPerPage(Integer feedbackRowPerPage) {
        this.feedbackRowPerPage = feedbackRowPerPage;
    }

    public Integer getFeedbackInfoRowPerPage() {
        return this.feedbackInfoRowPerPage;
    }

    public void setFeedbackInfoRowPerPage(Integer feedbackInfoRowPerPage) {
        this.feedbackInfoRowPerPage = feedbackInfoRowPerPage;
    }

    public String getTypeIndex() {
        return this.typeIndex;
    }

    public void setTypeIndex(String typeIndex) {
        this.typeIndex = typeIndex;
    }

    public Integer getTagRowPerPage() {
        return this.tagRowPerPage;
    }

    public void setTagRowPerPage(Integer tagRowPerPage) {
        this.tagRowPerPage = tagRowPerPage;
    }

    public Integer getCouponRowPerPage() {
        return this.couponRowPerPage;
    }

    public void setCouponRowPerPage(Integer couponRowPerPage) {
        this.couponRowPerPage = couponRowPerPage;
    }

    public Integer getReviewPageRowPerPage() {
        return this.reviewPageRowPerPage;
    }

    public void setReviewPageRowPerPage(Integer reviewPageRowPerPage) {
        this.reviewPageRowPerPage = reviewPageRowPerPage;
    }
}
